<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="/Public/static/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="/Public/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-form-pane" style="width:90%;padding-left: 5%;">
	<div class="layui-form-item">
	<label class="layui-form-label" for="week"><b style="color: red">* </b>星期</label>
	<div class="layui-input-block">
		<select name="week"  lay-verify="required" lay-verType="msg"   id="week" >
			<option value="">请选择星期</option>
			<option value=monday selected >星期一</option>
<option value=tuesday  >星期二</option>
<option value=wednesday  >星期三</option>

		</select>
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" ><b style="color: red">* </b>性别</label>
	<div class="layui-input-block">
		<input type="radio" name="genderdata" value="male" title="男" checked >
<input type="radio" name="genderdata" value="female" title="女"  >

	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="textarea"><b style="color: red">* </b>内容</label>
	<div class="layui-input-block">
		<textarea name="textarea" placeholder="内容" id="textarea" class="layui-textarea"  lay-verify="required" lay-verType="tips"   >{$info.textarea}</textarea>
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="image"><b style="color: red">* </b>图片</label>
	<div class="layui-input-block">
		<input type="text" readonly style="cursor: pointer" name="image" id="image" placeholder="图片"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
		<img src="" id="image_show" alt="图片" style="height: 100px;width: auto;position: absolute;z-index: 10;border: 1px dashed #d2d2d2;display: none">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="attachfile"><b style="color: red">* </b>附件</label>
	<div class="layui-input-block">
		<input type="text" readonly style="cursor: pointer" name="attachfile" id="attachfile" placeholder="附件"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="keywords"><b style="color: red">* </b>关键字</label>
	<div class="layui-input-block">
		<input type="text" name="keywords" id="keywords" placeholder="关键字"  lay-verify="required" lay-verType="tips"   autocomplete="off"  maxlength="100" value=""  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="price"><b style="color: red">* </b>价格</label>
	<div class="layui-input-block">
		<input type="number" name="price" id="price" placeholder="价格"  lay-verify="required|number" lay-verType="tips"   autocomplete="off"  step="0.01" value="0.00"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="startdate"><b style="color: red">* </b>开始日期</label>
	<div class="layui-input-block">
		<input type="text" readonly name="startdate" id="startdate" placeholder="年-月-日 时:分:秒"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="activitytime"><b style="color: red">* </b>活动时间(datetime)</label>
	<div class="layui-input-block">
		<input type="text" readonly name="activitytime" id="activitytime" placeholder="年-月-日 时:分:秒"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="year"><b style="color: red">* </b>年</label>
	<div class="layui-input-block">
		<input type="text" readonly name="year" id="year" placeholder="年-月-日 时:分:秒"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="times"><b style="color: red">* </b>时间</label>
	<div class="layui-input-block">
		<input type="text" readonly name="times" id="times" placeholder="年-月-日 时:分:秒"  lay-verify="required" lay-verType="tips"   autocomplete="off"  class="layui-input">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="switch">上架状态</label>
	<div class="layui-input-block">
		<input type="checkbox" lay-filter="switch" id="switch" title="" lay-skin="switch" lay-text="正常|下架" checked>
		<input type="hidden" name="switch" value="1">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="ttswitch">开关</label>
	<div class="layui-input-block">
		<input type="checkbox" lay-filter="ttswitch" id="ttswitch" title="" lay-skin="switch" lay-text="ON|OFF" >
		<input type="hidden" name="ttswitch" value="0">
	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" ><b style="color: red">* </b>测试复选</label>
	<div class="layui-input-block">
		<input class="teststate"
                     type="checkbox" name="teststate[]" title="选项1" value="1" lay-skin="primary"   checked >
<input class="teststate"
                     type="checkbox" name="teststate[]" title="选项2" value="2" lay-skin="primary"    >
<input class="teststate"
                     type="checkbox" name="teststate[]" title="选项3" value="3" lay-skin="primary"    >

	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" >爱好</label>
	<div class="layui-input-block">
		<input class="test2state"
                     type="checkbox" name="test2state[]" title="唱歌" value="0" lay-skin="primary"    >
<input class="test2state"
                     type="checkbox" name="test2state[]" title="跳舞" value="1" lay-skin="primary"    >
<input class="test2state"
                     type="checkbox" name="test2state[]" title="嫖娼" value="2" lay-skin="primary"   checked >

	</div>
</div><div class="layui-form-item">
	<label class="layui-form-label" for="editor_content">富文本</label>
	<div class="layui-input-block">
		<textarea name="editor_content" placeholder="富文本" id="editor_content" class="layui-textarea"  >{$info.editor_content|htmlspecialchars_decode}</textarea>
	</div>
</div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="addData">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script type="text/javascript" src="/Public/static/js/jquery-3.2.0.min.js"></script>
<script type="text/javascript" src="/Public/static/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['form','layer','laydate','upload','layedit'],function(){
        let form = layui.form,
		laydate = layui.laydate,
		upload = layui.upload,
            layedit = layui.layedit,
        layer = parent.layer === undefined ? layui.layer : top.layer;

        
upload.render({
            elem: "#image"
            ,url: "/admin/FileUpload/upload"
            ,before:function(){
                layer.msg("图片上传中",{icon:16});
            }
            ,done: function(res){
                let item = this.item;
                layer.closeAll();
                if(res.code === 0){
                    layer.msg("上传成功",{icon:1});
                    $(item).val(res.data.src);
                }else{
                    layer.alert(res.msg);
                }
            }
        });
        $("#image").hover(function(){
            let _this = $(this);
            if(_this.val() !== ''){
                $('#image_show').attr("src",_this.val()).slideDown();
            }
        },function(){
            $('#image_show').slideUp();
        });
        

upload.render({
            elem: "#attachfile"
            ,url: "/admin/FileUpload/uploadfile"
            ,accept: "file"
            ,before:function(){
                layer.msg("文件上传中",{icon:16});
            }
            ,done: function(res){
                let item = this.item;
                layer.closeAll();
                if(res.code === 0){
                    layer.msg("上传成功",{icon:1});
                    $(item).val(res.data.src);
                }else{
                    layer.alert(res.msg);
                }
            }
        });

laydate.render({
                          elem: '#startdate'
                          ,theme: '#01AAED'
                          ,type: 'date'
                          ,trigger: 'click'
                        });

laydate.render({
                          elem: '#activitytime'
                          ,theme: '#01AAED'
                          ,type: 'datetime'
                          ,trigger: 'click'
                        });

laydate.render({
                          elem: '#year'
                          ,theme: '#01AAED'
                          ,type: 'year'
                          ,trigger: 'click'
                        });

laydate.render({
                          elem: '#times'
                          ,theme: '#01AAED'
                          ,type: 'time'
                          ,trigger: 'click'
                        });

form.on('switch(switch)', function(data){
                            let v = '0';
                            if(data.elem.checked) v = '1';
                            $('input[name=switch]').val(v);
                        }); 

form.on('switch(ttswitch)', function(data){
                            let v = '0';
                            if(data.elem.checked) v = '1';
                            $('input[name=ttswitch]').val(v);
                        }); 


                    let editor_content = layedit.build('editor_content', {
                        uploadImage: {url: '/admin/FileUpload/upload', type: 'post'},
                        height:200
                    });
                    $("iframe[textarea=editor_content]").contents().find("body").blur(function(){
            layedit.sync(editor_content);
        });
                


        form.on("submit(addData)",function(){
            let index = layer.msg('数据提交中，请稍候',{icon: 16,time:false});
            $.post("/admin/Test/add",{para:$('form').serialize()},function(res){
                window.parent.window.parent.toast(res.info,res.code);
                layer.close(index);
                if(0 === res.code){
                    parent.layer.closeAll();
                    window.parent.tablist.reload();
                }
            });
            return false;
        });
    });
</script>
</body>
</html>